<?php
/**
 * Copyright (c) Company 贵州汉图数通信息技术有限公司
 * Department 研发&产品设计部-研发部
 * Author: starsphp
 * Created by PhpStorm
 * Date 2022-1-6
 * Time 18:21
 */

namespace app\im\controller;

use app\common\model\im\MessageModel;
use app\common\model\im\RecentSessionModel;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\response\Json;

/**
 * 消息相关类
 * Class Message
 * @packge app\im\controller
 **/
class Message
{
    /**
     * 获取消息会话列表
     * @return Json
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getLists()
    {
        return apiSuccess(RecentSessionModel::getOwnLists(9));
    }
    
    // 测试
    public function send()
    {
        // $data = [
        //     'from_type' => 'shop',
        //     'from_id' => 9,
        //     'to_type' => 'customer',
        //     'to_id' => 8,
        //     'content' => '测试，商户-》客户'
        // ];
        // halt(MessageModel::findOrEmpty(2)->append(['from', 'to'])->toArray());
        // $m = MessageModel::sendSave($data);
        // halt($m->toArray());
        // halt($m->append(['from', 'to'])->toArray());
    }
    
    // 测试
    public function recentSession()
    {
        // $rsmOwn = [
        //     'own_id' => 9,
        //     'own_type' => 'shop',
        //     'other_id' => 8,
        //     'other_type' => 'customer'
        // ];
        // $rsmOther = [
        //     'own_id' => 8,
        //     'own_type' => 'customer',
        //     'other_id' => 9,
        //     'other_type' => 'shop'
        // ];
        // $rsmOther['num'] = 1;
        // halt(RecentSessionModel::sendSave($rsmOwn), RecentSessionModel::sendSave($rsmOther));
        // RecentSessionModel::sendSave($rsmOwn);
        // RecentSessionModel::sendSave($rsmOther);
    }
}